package bingo.component.dhtmlxgrid.config;

import org.apache.commons.lang.StringUtils;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class ParamConverter implements Converter {

	public void marshal(Object source,
			HierarchicalStreamWriter writer,
			MarshallingContext context) {
		Param param = (Param)source;
		if (StringUtils.isNotEmpty(param.getValue())) {
			writer.setValue(param.getValue());
		}
			
	}

	public Object unmarshal(HierarchicalStreamReader reader,
			UnmarshallingContext context) {
		Param param = new Param();
		if (StringUtils.isNotEmpty(reader.getValue())) {
			param.setValue(reader.getValue());
		}
		return param;
	}
	@SuppressWarnings("unchecked")
	public boolean canConvert(Class clazz) {
		return clazz.equals(Param.class);
	}

}
